package com.tedu.interceptor.config;

import com.tedu.interceptor.interceptor.MyInterceptor;
import com.tedu.interceptor.interceptor.MyInterceptor1;
import com.tedu.interceptor.interceptor.MyInterceptor2;
import com.tedu.interceptor.interceptor.MyInterceptor3;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class Config implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //添加一个拦截器
        //默认添加的拦截器是所有请求路径全部进行拦截
//        registry.addInterceptor(new MyInterceptor());

        /*
            可以为拦截器指定拦截路径，那么仅当请求该路径是进行拦截

            http://localhost:8080/index.html    不进行拦截
            http://localhost:8080/users/login   不进行拦截
            http://localhost:8080/users/reg     进行拦截
         */
//        registry.addInterceptor(new MyInterceptor())
//                .addPathPatterns("/users/reg");

        /*
            可以为拦截器同时指定多个拦截路径
            http://localhost:8080/index.html     进行拦截
            http://localhost:8080/users/login   不进行拦截
            http://localhost:8080/users/reg     进行拦截
         */
//        registry.addInterceptor(new MyInterceptor())
//                .addPathPatterns("/users/reg" , "/index.html");

        /*
            为拦截器指定一类路径的拦截，可以使用"**"模糊匹配一部分路径
            http://localhost:8080/index.html    不进行拦截
            http://localhost:8080/users/login   进行拦截
            http://localhost:8080/users/reg     进行拦截
            http://localhost:8080/users/delete     进行拦截
            http://localhost:8080/weibo/insert  不进行拦截
         */
//        registry.addInterceptor(new MyInterceptor())
//                .addPathPatterns("/users/**");// "/users/任意路径"
       /* registry.addInterceptor(new MyInterceptor())
                .addPathPatterns("/users/**")
                .excludePathPatterns("/users/login");//排除该路径*/
        registry.addInterceptor(new MyInterceptor1());
        registry.addInterceptor(new MyInterceptor2());
        registry.addInterceptor(new MyInterceptor3());
    }
}



